/**
 * @param {string} s
 * @return {string}
 */
var lastSubstring = function (s) {
    let left=0
    let right = left+1,step=0
    while(right+step<s.length){
      if(s[left+step]<s[right+step]){
        left=Math.max(left+step+1,right)
        right++
        step=0
      }else if(s[left+step]==s[right+step]){
        step++
      }else {
        right+=step+1
        step=0
      }
    }

    return s.slice(left)
};

lastSubstring('abab')